---
layout: "default"
title: "Operator: %"
description: "Swift documentation for the '%' operator."
root: "/v4.2"
---

<code class="language-swift"> operator % {
    associativity left
    precedence 
}</code>

<h3>Declarations</h3>

<div class="declaration" id="func-pct_-int-rhs_-int">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-pct_-int-rhs_-int">func %(<wbr>_:<wbr> Int, rhs: Int)</a>
        
<div class="comment collapse" id="comment-func-pct_-int-rhs_-int"><div class="p">
    <p>Returns the remainder of dividing the first value by the second.</p>

<p>The result of the modulo operator (<code>%</code>) has the same sign as <code>lhs</code> and is
less than <code>rhs.magnitude</code>.</p>

<pre><code class="language-swift">let x = 22 % 5
// x == 2
let y = 22 % -5
// y == 2
let z = -22 % -5
// z == -2</code></pre>

<p>For any two integers <code>a</code> and <code>b</code>, their quotient <code>q</code>, and their remainder
<code>r</code>, <code>a == b * q + r</code>.</p>

<p><strong>Parameters:</strong>
  <strong>lhs:</strong> The value to divide.
  <strong>rhs:</strong> The value to divide <code>lhs</code> by. <code>rhs</code> must not be zero.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func %(lhs: Int, rhs: Int) -&gt; Int</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-pct_-int8-rhs_-int8">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-pct_-int8-rhs_-int8">func %(<wbr>_:<wbr> Int8, rhs: Int8)</a>
        
<div class="comment collapse" id="comment-func-pct_-int8-rhs_-int8"><div class="p">
    <p>Returns the remainder of dividing the first value by the second.</p>

<p>The result of the modulo operator (<code>%</code>) has the same sign as <code>lhs</code> and is
less than <code>rhs.magnitude</code>.</p>

<pre><code class="language-swift">let x = 22 % 5
// x == 2
let y = 22 % -5
// y == 2
let z = -22 % -5
// z == -2</code></pre>

<p>For any two integers <code>a</code> and <code>b</code>, their quotient <code>q</code>, and their remainder
<code>r</code>, <code>a == b * q + r</code>.</p>

<p><strong>Parameters:</strong>
  <strong>lhs:</strong> The value to divide.
  <strong>rhs:</strong> The value to divide <code>lhs</code> by. <code>rhs</code> must not be zero.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func %(lhs: Int8, rhs: Int8) -&gt; Int8</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-pct_-int16-rhs_-int16">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-pct_-int16-rhs_-int16">func %(<wbr>_:<wbr> Int16, rhs: Int16)</a>
        
<div class="comment collapse" id="comment-func-pct_-int16-rhs_-int16"><div class="p">
    <p>Returns the remainder of dividing the first value by the second.</p>

<p>The result of the modulo operator (<code>%</code>) has the same sign as <code>lhs</code> and is
less than <code>rhs.magnitude</code>.</p>

<pre><code class="language-swift">let x = 22 % 5
// x == 2
let y = 22 % -5
// y == 2
let z = -22 % -5
// z == -2</code></pre>

<p>For any two integers <code>a</code> and <code>b</code>, their quotient <code>q</code>, and their remainder
<code>r</code>, <code>a == b * q + r</code>.</p>

<p><strong>Parameters:</strong>
  <strong>lhs:</strong> The value to divide.
  <strong>rhs:</strong> The value to divide <code>lhs</code> by. <code>rhs</code> must not be zero.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func %(lhs: Int16, rhs: Int16) -&gt; Int16</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-pct_-int32-rhs_-int32">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-pct_-int32-rhs_-int32">func %(<wbr>_:<wbr> Int32, rhs: Int32)</a>
        
<div class="comment collapse" id="comment-func-pct_-int32-rhs_-int32"><div class="p">
    <p>Returns the remainder of dividing the first value by the second.</p>

<p>The result of the modulo operator (<code>%</code>) has the same sign as <code>lhs</code> and is
less than <code>rhs.magnitude</code>.</p>

<pre><code class="language-swift">let x = 22 % 5
// x == 2
let y = 22 % -5
// y == 2
let z = -22 % -5
// z == -2</code></pre>

<p>For any two integers <code>a</code> and <code>b</code>, their quotient <code>q</code>, and their remainder
<code>r</code>, <code>a == b * q + r</code>.</p>

<p><strong>Parameters:</strong>
  <strong>lhs:</strong> The value to divide.
  <strong>rhs:</strong> The value to divide <code>lhs</code> by. <code>rhs</code> must not be zero.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func %(lhs: Int32, rhs: Int32) -&gt; Int32</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-pct_-int64-rhs_-int64">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-pct_-int64-rhs_-int64">func %(<wbr>_:<wbr> Int64, rhs: Int64)</a>
        
<div class="comment collapse" id="comment-func-pct_-int64-rhs_-int64"><div class="p">
    <p>Returns the remainder of dividing the first value by the second.</p>

<p>The result of the modulo operator (<code>%</code>) has the same sign as <code>lhs</code> and is
less than <code>rhs.magnitude</code>.</p>

<pre><code class="language-swift">let x = 22 % 5
// x == 2
let y = 22 % -5
// y == 2
let z = -22 % -5
// z == -2</code></pre>

<p>For any two integers <code>a</code> and <code>b</code>, their quotient <code>q</code>, and their remainder
<code>r</code>, <code>a == b * q + r</code>.</p>

<p><strong>Parameters:</strong>
  <strong>lhs:</strong> The value to divide.
  <strong>rhs:</strong> The value to divide <code>lhs</code> by. <code>rhs</code> must not be zero.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func %(lhs: Int64, rhs: Int64) -&gt; Int64</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-pct_-uint-rhs_-uint">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-pct_-uint-rhs_-uint">func %(<wbr>_:<wbr> UInt, rhs: UInt)</a>
        
<div class="comment collapse" id="comment-func-pct_-uint-rhs_-uint"><div class="p">
    <p>Returns the remainder of dividing the first value by the second.</p>

<p>The result of the modulo operator (<code>%</code>) has the same sign as <code>lhs</code> and is
less than <code>rhs.magnitude</code>.</p>

<pre><code class="language-swift">let x = 22 % 5
// x == 2
let y = 22 % -5
// y == 2
let z = -22 % -5
// z == -2</code></pre>

<p>For any two integers <code>a</code> and <code>b</code>, their quotient <code>q</code>, and their remainder
<code>r</code>, <code>a == b * q + r</code>.</p>

<p><strong>Parameters:</strong>
  <strong>lhs:</strong> The value to divide.
  <strong>rhs:</strong> The value to divide <code>lhs</code> by. <code>rhs</code> must not be zero.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func %(lhs: UInt, rhs: UInt) -&gt; UInt</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-pct_-uint8-rhs_-uint8">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-pct_-uint8-rhs_-uint8">func %(<wbr>_:<wbr> UInt8, rhs: UInt8)</a>
        
<div class="comment collapse" id="comment-func-pct_-uint8-rhs_-uint8"><div class="p">
    <p>Returns the remainder of dividing the first value by the second.</p>

<p>The result of the modulo operator (<code>%</code>) has the same sign as <code>lhs</code> and is
less than <code>rhs.magnitude</code>.</p>

<pre><code class="language-swift">let x = 22 % 5
// x == 2
let y = 22 % -5
// y == 2
let z = -22 % -5
// z == -2</code></pre>

<p>For any two integers <code>a</code> and <code>b</code>, their quotient <code>q</code>, and their remainder
<code>r</code>, <code>a == b * q + r</code>.</p>

<p><strong>Parameters:</strong>
  <strong>lhs:</strong> The value to divide.
  <strong>rhs:</strong> The value to divide <code>lhs</code> by. <code>rhs</code> must not be zero.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func %(lhs: UInt8, rhs: UInt8) -&gt; UInt8</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-pct_-uint16-rhs_-uint16">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-pct_-uint16-rhs_-uint16">func %(<wbr>_:<wbr> UInt16, rhs: UInt16)</a>
        
<div class="comment collapse" id="comment-func-pct_-uint16-rhs_-uint16"><div class="p">
    <p>Returns the remainder of dividing the first value by the second.</p>

<p>The result of the modulo operator (<code>%</code>) has the same sign as <code>lhs</code> and is
less than <code>rhs.magnitude</code>.</p>

<pre><code class="language-swift">let x = 22 % 5
// x == 2
let y = 22 % -5
// y == 2
let z = -22 % -5
// z == -2</code></pre>

<p>For any two integers <code>a</code> and <code>b</code>, their quotient <code>q</code>, and their remainder
<code>r</code>, <code>a == b * q + r</code>.</p>

<p><strong>Parameters:</strong>
  <strong>lhs:</strong> The value to divide.
  <strong>rhs:</strong> The value to divide <code>lhs</code> by. <code>rhs</code> must not be zero.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func %(lhs: UInt16, rhs: UInt16) -&gt; UInt16</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-pct_-uint32-rhs_-uint32">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-pct_-uint32-rhs_-uint32">func %(<wbr>_:<wbr> UInt32, rhs: UInt32)</a>
        
<div class="comment collapse" id="comment-func-pct_-uint32-rhs_-uint32"><div class="p">
    <p>Returns the remainder of dividing the first value by the second.</p>

<p>The result of the modulo operator (<code>%</code>) has the same sign as <code>lhs</code> and is
less than <code>rhs.magnitude</code>.</p>

<pre><code class="language-swift">let x = 22 % 5
// x == 2
let y = 22 % -5
// y == 2
let z = -22 % -5
// z == -2</code></pre>

<p>For any two integers <code>a</code> and <code>b</code>, their quotient <code>q</code>, and their remainder
<code>r</code>, <code>a == b * q + r</code>.</p>

<p><strong>Parameters:</strong>
  <strong>lhs:</strong> The value to divide.
  <strong>rhs:</strong> The value to divide <code>lhs</code> by. <code>rhs</code> must not be zero.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func %(lhs: UInt32, rhs: UInt32) -&gt; UInt32</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-pct_-uint64-rhs_-uint64">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-pct_-uint64-rhs_-uint64">func %(<wbr>_:<wbr> UInt64, rhs: UInt64)</a>
        
<div class="comment collapse" id="comment-func-pct_-uint64-rhs_-uint64"><div class="p">
    <p>Returns the remainder of dividing the first value by the second.</p>

<p>The result of the modulo operator (<code>%</code>) has the same sign as <code>lhs</code> and is
less than <code>rhs.magnitude</code>.</p>

<pre><code class="language-swift">let x = 22 % 5
// x == 2
let y = 22 % -5
// y == 2
let z = -22 % -5
// z == -2</code></pre>

<p>For any two integers <code>a</code> and <code>b</code>, their quotient <code>q</code>, and their remainder
<code>r</code>, <code>a == b * q + r</code>.</p>

<p><strong>Parameters:</strong>
  <strong>lhs:</strong> The value to divide.
  <strong>rhs:</strong> The value to divide <code>lhs</code> by. <code>rhs</code> must not be zero.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func %(lhs: UInt64, rhs: UInt64) -&gt; UInt64</code>
    
    
</div></div>
</div>
